package org.medusa.network;

import java.util.concurrent.atomic.AtomicBoolean;

import org.medusa.packet.blob.BasePacket;

//1.接口需要完善
public abstract class Connector<PacketType extends BasePacket> {
	
	private AtomicBoolean running = new AtomicBoolean(false);
	
	protected boolean is_running() {
		return this.running.get();
	}

	protected boolean set_state_running() {
		return this.running.compareAndSet(false, true);
	}

	protected boolean set_state_stopped() {
		return this.running.compareAndSet(true, false);
	}
	
	public abstract Error Connect(String ip, int port, int timeout_ms);
	public abstract void Reconnect(int sleep, String tip);
	public abstract void Close();

	public abstract boolean IsConnected();
	
	public abstract void SendPacket(final PacketType outpack);
}
